#include "Turtle.h"

Turtle::Turtle(string ts)
{
	turtleString = ts;
	position = point3(0.0f,0.0f,0.0f);
	direction = point3(0.0f,1.0f,0.0f);
	Index = 0;
	while(!stateStack.empty())
	{
		stateStack.pop();
	}
}

char Turtle::getCommand()
{
	Index++;
	return turtleString[Index-1];
	
}

bool Turtle::isEnd()
{
	return Index == turtleString.size();
}

int Turtle::getIndex()
{
	return Index;
}

void Turtle::setPosition(point3 pos)
{
	position = pos;
}

point3 Turtle::getPosition()
{
	return position;
}

point3 Turtle::getDirection()
{
	return direction;
}

void Turtle::forward(int len)
{
	position = position + direction * len;
}

void Turtle::rotateZ(float angle)
{
	point4 dir = point4(direction,0.0f);
	dir = Angel::RotateZ(angle)*dir;
	direction = point3(dir.x,dir.y,dir.z);
}

void Turtle::rotateX(float angle)
{
	point4 dir = point4(direction,0.0f);
	dir = Angel::RotateX(angle)*dir;
	direction = point3(dir.x,dir.y,dir.z);
}

void Turtle::rotateY(float angle)
{
	point4 dir = point4(direction,0.0f);
	dir = Angel::RotateY(angle)*dir;
	direction = point3(dir.x,dir.y,dir.z);
}

void Turtle::pushState()
{
	stateStack.push(pair<point3,point3> (position,direction));
}

void Turtle::popState()
{
	position = stateStack.top().first;
	direction = stateStack.top().second;
	stateStack.pop();
}

void Turtle::turnAround()
{
	direction = -direction;
}




